import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

public class Main {
    public static void main(String[] args) {
        ArrayList<Integer> arrayList=new ArrayList<>();
        arrayList.add(10);
        arrayList.add(20);
        arrayList.add(30);
        arrayList.add(40);
        System.out.println(arrayList);//第一种遍历方式
//        第二种
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i)+" ");
        }
        System.out.println();
//        第三种 for-each
        for (Integer X: arrayList) {
            System.out.print(X+" ");
        }
        System.out.println();
//        第四种  迭代器
        Iterator<Integer> iterator= arrayList.iterator();
        while(iterator.hasNext()){
            System.out.print(iterator.next()+" ");
        }
        System.out.println();
//        第五种   ListIterator ->专门用于list的迭代器
        ListIterator<Integer> iteratorListIterator=arrayList.listIterator();
        while(iteratorListIterator.hasNext()){
            System.out.print(iteratorListIterator.next()+" ");
        }
        System.out.println();
//        第六种  从后向前遍历
        ListIterator <Integer> integerListIterator1=arrayList.listIterator(arrayList.size());
        while (integerListIterator1.hasPrevious()){
            System.out.print(integerListIterator1.previous()+" ");
        }
        System.out.println();
    }
}